package com.example.hospitallogin.modules.register.controller;

import com.example.hospitallogin.assembly.BaseResponse;
import com.example.hospitallogin.assembly.CustomResultCode;
import com.example.hospitallogin.modules.register.bff.RegisterImpl;
import com.example.hospitallogin.interceptor.DictType;
import com.example.hospitallogin.modules.register.dto.RegisterHospitalReq;
import com.example.hospitallogin.modules.register.dto.RegisterUserReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author qiancheng@cqxyy.net
 * @date 2022/9/15
 */
@RestController
@RequestMapping("/register")
@Api(tags = "账号注册")
@Validated
public class RegisterController {
    private final static Map<String, List<DictType>> enumDictData = new HashMap<>(5);

    @Autowired
    RegisterImpl register;

    @ApiOperation(value = "医院账号申请")
    @RequestMapping(path = "/hospital",method = RequestMethod.POST)
    public BaseResponse registerHospital(@RequestBody @Valid RegisterHospitalReq req){
        String msg = register.registerHospital(req);
        if(!msg.equals("")){
            return BaseResponse.fail(CustomResultCode.REGISTERERROR,msg);
        }
        return BaseResponse.success();
    };

    @ApiOperation(value = "用户账号申请")
    @RequestMapping(path = "/user",method = RequestMethod.POST)
    public BaseResponse registerUser(@RequestBody @Valid RegisterUserReq req){
        String msg = register.registerUser(req);
        if (msg.equals("此手机号已被注册")){
            return BaseResponse.fail(CustomResultCode.REGISTERERROR,msg);
        }
        return BaseResponse.success();
    }

}
